#include "config_main.h"
#ifdef DDENN_INS_ACCELEROMETER_AM9
/*
 * ins_accelerometer_am9.cpp
 *
 *  Created on: 08.06.2009
 *      Author: Admin
 */
#include "ins_accelerometer_am9.h"


float DdennAm9::Am9NegMax=0;
float DdennAm9::Am9PosMax=0;

void DdennAm9::RegisterDdennAm9(){
	  XPLMRegisterCommandHandler(XPLMCreateCommand(
              "ddenn/instruments/am9/reset",
              "It resets AM-9 accelerometer to zero") ,
							  Am9Reset,1, NULL);
	  XPLMRegisterDataAccessor( "ddenn/instruments/am9/main" ,    xplmType_Float, 0,NULL,NULL,
			  GetInsAm9Main, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	  XPLMRegisterDataAccessor( "ddenn/instruments/am9/maxneg" ,    xplmType_Float, 0,NULL,NULL,
			  GetInsAm9NegMax, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

	  XPLMRegisterDataAccessor( "ddenn/instruments/am9/maxpos" ,    xplmType_Float, 0,NULL,NULL,
			  GetInsAm9PosMax, NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);

}
void DdennAm9::UnregisterDdennAm9(){

	 XPLMUnregisterCommandHandler(XPLMFindCommand( "ddenn/instruments/am9/reset") ,
								  Am9Reset,1, NULL);
		  XPLMUnregisterDataAccessor( XPLMFindDataRef("ddenn/instruments/am9/main") );

		  XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/am9/maxneg"));

		  XPLMUnregisterDataAccessor(  XPLMFindDataRef("ddenn/instruments/am9/maxpos") );

}

bool DdennAm9::IsPowered(){return true;}

void DdennAm9::OnCrash(){
	Am9NegMax=0;
	Am9PosMax=0;
}

int DdennAm9::Am9Reset(
                                   XPLMCommandRef       inCommand,
                                   XPLMCommandPhase     inPhase,
                                   void *               inRefcon)
{
	Am9NegMax=0;
	Am9PosMax=0;
	return 0;
}
float DdennAm9::GetInsAm9NegMax ( void *               inRefcon){
	return Am9NegMax;
}
float DdennAm9::GetInsAm9Main ( void *               inRefcon){
	float i = GetDataRefF("sim/flightmodel/position/local_ax");
	if (i<Am9NegMax) {Am9NegMax=i;};
	if (i>Am9PosMax) {Am9PosMax=i;};
	return i;

}
float DdennAm9::GetInsAm9PosMax ( void *               inRefcon){
	return Am9PosMax;
}


#endif
